﻿<UserControl x:Class="BrainTechLLC.FolderExplorer.FolderExplorerControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:dragdrop="clr-namespace:DragDropLibrary;assembly=DragAndDrop"             
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    xmlns:WPF="clr-namespace:BrainTechLLC.WPF;assembly=BrainTechLLC.WPF"
    KeyUp="UserControl_KeyUp"             
    xmlns:my="clr-namespace:BrainTechLLC.FolderExplorer" 
    KeyDown="UserControl_KeyDown">
    <UserControl.Resources>
        <WPF:VisibilityConverter x:Key="VisibilityConverter" />
        <ContextMenu x:Key="contextMenuShared" x:Shared="true" Tag="{Binding}">
            <MenuItem Tag="{Binding}" x:Name="mnuOpenFolder" Header="_Open Folder" Click="mnuOpenFolder_Click"/>
            <MenuItem Tag="{Binding}" x:Name="mnuShowDirSizes" Header="Show Directory _Sizes of Selected" Click="mnuShowDirSizes_Click"/>
            <MenuItem Tag="{Binding}" x:Name="mnuSelectAll" Header="Select _All" Click="mnuSelectAll_Click"/>
            <MenuItem Tag="{Binding}" x:Name="mnuClearSelection" Header="_Clear Selection" Click="mnuClearSelection_Click"/>
            <MenuItem Tag="{Binding}" x:Name="mnuExpandChildren" Header="_Expand Children" Click="mnuExpandChildren_Click"/>
            <MenuItem Tag="{Binding}" x:Name="mnuCollapseAll" Header="Collapse A_ll" Click="mnuCollapseAll_Click"/>
            <Separator />
            <MenuItem Tag="{Binding}" x:Name="mnuNewDirectory" Header="Create New _Directory" Click="mnuNewDirectory_Click" />
            <MenuItem Tag="{Binding}" x:Name="mnuRename" Header="_Rename Directory" Click="mnuRename_Click" />
            <Separator />
            <MenuItem Tag="{Binding}" x:Name="mnuFindFoldersToDelete" Header="_Find bin/obj Folders to Delete" Click="mnuFindFoldersToDelete_Click"/>
            <MenuItem Tag="{Binding}" x:Name="mnuDeleteSelected" Header="_Delete Checked Folders" Click="mnuDeleteSelected_Click"/>
            <MenuItem Tag="{Binding}" x:Name="mnuDeleteAllSvn" Header="Delete all .s_vn Sub-Folders" Click="mnuDeleteAllSvn_Click"/>
        </ContextMenu>
        <Style TargetType="{x:Type TreeViewItem}" x:Key="treeViewItemStyle">
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
            <Setter Property="FontWeight" Value="Normal" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="Background" Value="White"/>
            <Setter Property="Foreground" Value="Black"/>
            <Setter Property="DataContext" Value="{Binding}" />
            <Setter Property="Tag" Value="{Binding}" />
        </Style>
        <Style TargetType="{x:Type my:AltGrid}" x:Key="gridHighlight">
            <Setter Property="Background" Value="White"/>
            <Setter Property="Margin" Value="0,0,0,0"/>
            <!--<Setter Property="TextElement.FontSize" Value="9"/>-->
            <Setter Property="TextBlock.Foreground" Value="Black"/>
            <Style.Triggers>
                <Trigger Property="Depth" Value="1">
                    <Setter Property="Background" Value="LightCyan"/>
                </Trigger>
                <Trigger Property="Depth" Value="2">
                    <Setter Property="Background" Value="LightYellow"/>
                </Trigger>
                <Trigger Property="Depth" Value="3">
                    <Setter Property="Background" Value="LightPink"/>
                </Trigger>
                <Trigger Property="IsFolderSelected" Value="True">
                    <Setter Property="Background" Value="DarkBlue"/>
                    <Setter Property="TextBlock.Foreground" Value="Yellow"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <!--SubFoldersRequest-->
        <HierarchicalDataTemplate DataType="{x:Type my:FolderViewModel}" ItemsSource="{Binding Path=SubFolders}">
            <my:AltGrid x:Name="gridTVI" Loaded="gridTVI_Loaded" Folder="{Binding}" HorizontalAlignment="Stretch" 
                      dragdrop:DragAndDrop.DropEnabled="true" Tag="{Binding}" dragdrop:DragAndDrop.RegisterDropTargetName="TreeView"                                            
                      Style="{StaticResource gridHighlight}" Height="16" my:AltGrid.ContextMenu="{StaticResource contextMenuShared}"                      
                      MouseLeftButtonDown="tvRoot_MouseLeftButtonDown" MouseRightButtonDown="gridMouseRightButtonDown_Click"                      
                      KeyDown="UserControl_KeyDown" KeyUp="UserControl_KeyUp">
                <my:AltGrid.ColumnDefinitions>
                    <ColumnDefinition Width="18"/>
                    <ColumnDefinition Width="0.9*" MinWidth="120"/>
                    <ColumnDefinition Width="70"/>
                    <ColumnDefinition Width="40"/>
                    <ColumnDefinition Width="70"/>
                    <ColumnDefinition Width="40"/>
                    <ColumnDefinition Width="70"/>
                    <ColumnDefinition Width="40"/>
                </my:AltGrid.ColumnDefinitions>                
                <CheckBox Tag="{Binding}" x:Name="chk" IsChecked="{Binding Mode=TwoWay, Path=IsChecked}" Focusable="False" Click="chk_Click" Padding="0" Margin="0" Width="14" Height="14" />
                <!--<TextBlock Text="{Binding IsVisible}" HorizontalAlignment="Right" VerticalAlignment="Top" Canvas.ZIndex="99" Margin="-30,0,0,0"/>-->
                <Grid Grid.Column="1" HorizontalAlignment="Stretch" KeyDown="Grid_KeyDown" KeyUp="Grid_KeyUp">
                    <TextBox x:Name="txt" Text="{Binding Mode=TwoWay, Path=Name}" Tag="{Binding}" FontSize="9" Padding="2,0,2,0" BorderThickness="{Binding NotInEditModeThickness}" KeyDown="txt_KeyDown" AcceptsReturn="False" LostFocus="txt_LostFocus" Visibility="{Binding TextBoxEditVisible}" />
                    <TextBlock Tag="{Binding}" x:Name="txtBlock" Text="{Binding Path=Name}" Visibility="{Binding NotTextBoxEditVisible}" MouseLeftButtonUp="txtBlock_MouseLeftButtonUp" Focusable="False" />
                </Grid>

                <Grid Grid.Column="2" HorizontalAlignment="Stretch">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding FileCount}" VerticalAlignment="Center"/>
                        <TextBlock Text=" / " VerticalAlignment="Center"/>
                        <TextBlock Text="{Binding TotalFileCount}" VerticalAlignment="Center"/>
                    </StackPanel>
                </Grid>

                <Grid Grid.Column="3" HorizontalAlignment="Stretch">
                    <TextBlock Text="{Binding Depth}" VerticalAlignment="Center"/>
                </Grid>

                <Grid Grid.Column="4" HorizontalAlignment="Stretch">
                    <TextBlock Text="{Binding DirectoryDate}" VerticalAlignment="Center"/>
                </Grid>

                <Grid Grid.Column="5" HorizontalAlignment="Stretch">
                    <TextBlock Text="{Binding RecursiveSubDirectoryCount}" VerticalAlignment="Center"/>
                </Grid>

                <Grid Grid.Column="6" HorizontalAlignment="Stretch">
                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" Padding="4,0,0,0" Tag="{Binding}" x:Name="txtDirSize" Text="{Binding DirectorySize}" Visibility="{Binding DirectorySizeNonZero}" Focusable="False" />
                </Grid>

                <Grid Grid.Column="7" HorizontalAlignment="Stretch">
                    <CheckBox VerticalAlignment="Center" HorizontalAlignment="Right" Padding="4,0,0,0" Tag="{Binding}" x:Name="chkExclude" Focusable="False" IsChecked="{Binding Mode=TwoWay, Path=Exclude}" />
                </Grid>

            </my:AltGrid>
        </HierarchicalDataTemplate>
    </UserControl.Resources>
    <Grid VerticalAlignment="Stretch" Grid.Row="0" x:Name="mainGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" MinWidth="240" />
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Border BorderBrush="LightBlue" BorderThickness="0" Margin="0,0,3,0" SizeChanged="Border_SizeChanged" x:Name="border"
                    VerticalAlignment="Stretch">
            <Grid>
                <Grid HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="20" Margin="44,0,34,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="18"/>
                        <ColumnDefinition Width="0.9*" MinWidth="120"/>
                        <ColumnDefinition Width="70"/>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition Width="70"/>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition Width="70"/>
                        <ColumnDefinition Width="40"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" Text="" TextDecorations="Underline"
                               Cursor="Hand" x:Name="colSelected"/>
                    <TextBlock Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Folder" TextDecorations="Underline"
                               Cursor="Hand" x:Name="colFolder" MouseDown="colFolder_MouseDown"/>
                    <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Files" TextDecorations="Underline"
                               Cursor="Hand" x:Name="colFileCount"/>
                    <TextBlock Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Depth" TextDecorations="Underline"
                               Cursor="Hand" x:Name="coldDepth"/>
                    <TextBlock Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Date" TextDecorations="Underline"
                               Cursor="Hand" x:Name="colDate"/>
                    <TextBlock Grid.Column="5" VerticalAlignment="Center" HorizontalAlignment="Left" Text="Subdirs" TextDecorations="Underline"
                               Cursor="Hand" x:Name="colSubdirs"/>
                    <TextBlock Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Right" Text="Size" TextDecorations="Underline"
                               Cursor="Hand" x:Name="colSize"/>
                    <TextBlock Grid.Column="7" VerticalAlignment="Center" HorizontalAlignment="Right" Text="Exclude" TextDecorations="Underline"
                               Cursor="Hand" x:Name="colExclude"/>
                </Grid>
                <TreeView Margin="0,40,0,0" x:Name="treeView1" 
                              Background="LightCyan"
                              VerticalAlignment="Top"
                              ScrollViewer.VerticalScrollBarVisibility="Visible" 
                              ScrollViewer.HorizontalScrollBarVisibility="Auto" 
                              BorderBrush="Black" BorderThickness="1,1,1,1"                      
                              Padding="0"
                              dragdrop:DragAndDrop.DragEnabled="true"                                                        
                              IsTextSearchEnabled="True"                              
                              HorizontalAlignment="Stretch"
                              KeyDown="treeView1_KeyDown"
                              KeyUp="treeView1_KeyUp"                           
                              ScrollViewer.ScrollChanged="treeView1_ScrollChanged">
                    <TreeViewItem x:Name="tvRoot" Loaded="tvRoot_Loaded" Tag="{Binding}" Selected="tvRoot_Selected"
                              ItemsSource="{Binding Mode=OneWay, Path=SubFolders}"
                              PreviewKeyDown="tvRoot_PreviewKeyDown"                              
                                  Expanded="tvRoot_Expanded"
                              KeyDown="tvRoot_KeyDown" KeyUp="tvRoot_KeyUp"
                              ItemContainerStyle="{StaticResource treeViewItemStyle}"
                              HorizontalAlignment="Stretch">
                    </TreeViewItem>
                </TreeView>
            </Grid>
        </Border>
        <GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="3" BorderBrush="Blue" Foreground="Blue" Background="Blue"
                      x:Name="rightGridSplitter" Visibility="Collapsed" 
                      />
        <Grid Grid.Column="1" x:Name="rightGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="0.5*"/>
                <RowDefinition Height="0.5*"/>
            </Grid.RowDefinitions>
            <my:ShowFolderListView x:Name="showFolders" Margin="0,0,0,3" Folder="{Binding Mode=OneWay, ElementName=treeView1, Path=SelectedItem}" />
            <GridSplitter Height="3" Foreground="Green" Background="Green" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
            <my:ShowFilesListView x:Name="showFiles" Grid.Row="1" Folder="{Binding Mode=OneWay, ElementName=treeView1, Path=SelectedItem}" />
        </Grid>
    </Grid>
</UserControl>
